﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Salats
{
    public partial class GUI : Form
    {
        public Salat Sal = new Salat();

         public GUI()
        {
            InitializeComponent();
        }
        
        public GUI(Salat G)
        {
            InitializeComponent();
            Sal = G;
        }
        
        public void GUI_get_new_al(Salat G)
        {
            Sal = G;
        }

        private void GUI_Load(object sender, EventArgs e)
        {
            for (int i = 0; i < Sal.salat.Count; i++)
            {
                String s = Sal.salat[i].GetType().ToString();
                switch (s)
                {
                    case "Salats.WithMeat":
                        listBox1.Items.Add(((WithMeat)Sal.salat[i]).GetType() + " - " + ((WithMeat)Sal.salat[i]).GetName());
                        break;
                    case "Salats.WithFish":
                        listBox1.Items.Add(((WithFish)Sal.salat[i]).GetType() + " - " + ((WithFish)Sal.salat[i]).GetName());
                        break;
                    case "Salats.SalatWithFish":
                        listBox1.Items.Add(((SalatWithFish)Sal.salat[i]).GetType() + " - " + ((SalatWithFish)Sal.salat[i]).GetName());
                        break;
                    case "Salats.SalatWithMeat":
                        listBox1.Items.Add(((SalatWithMeat)Sal.salat[i]).GetMeat() + " - " + ((SalatWithMeat)Sal.salat[i]).GetName());
                        break;
                    case "Salats.AbstractVegetable":
                        listBox1.Items.Add(((AbstractVegetable)Sal.salat[i]).GetType() + " - " + ((AbstractVegetable)Sal.salat[i]).GetName());
                        break;
                }
            }

        }
        private void button1_Click(object sender, EventArgs e)
        {
            Add_salat CF = new Add_salat();
            
            CF.ShowDialog();

            Salat cF = CF.Sal;
            for (int i = 0; i < cF.salat.Count; i++)
            {
                String s = cF.salat[i].GetType().ToString();
                switch (s)
                {
                    case "Salats.WithMeat":
                        Sal.Add((WithMeat)cF.salat[i]);
                        break;
                    case "Salats.WithFish":
                        Sal.Add((WithFish)cF.salat[i]);
                        break;
                }
                
            }
            
            listBox1.Items.Clear();

            for (int i = 0; i < Sal.salat.Count; i++)
            {
                String s = Sal.salat[i].GetType().ToString();
                switch (s)
                {
                    case "Salats.WithMeat":
                        listBox1.Items.Add(((WithMeat)Sal.salat[i]).GetType() + " - " + ((WithMeat)Sal.salat[i]).GetName());
                        break;
                    case "Salats.WithFish":
                        listBox1.Items.Add(((WithFish)Sal.salat[i]).GetType() + " - " + ((WithFish)Sal.salat[i]).GetName());
                        break;

                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            int temp = listBox1.SelectedIndex;
            listBox1.Items.RemoveAt(temp);
            Sal.salat.RemoveAt(temp);
        }

        private void button3_Click_1(object sender, EventArgs e)
        {
            int i = listBox1.SelectedIndex;

            String s = Sal.salat[i].GetType().ToString();
            switch (s)
            {
                case "Salats.WithMeat":
                    MessageBox.Show("Название салата: " + ((WithMeat)Sal.salat[i]).GetName() + " [" + ((WithMeat)Sal.salat[i]).GetType() + "] \nколорийность: " + ((WithMeat)Sal.salat[i]).GetCalorie() + "\nмясо: " + ((WithMeat)Sal.salat[i]).GetMeat());
                    break;
                case "Salats.WithFish":
                    MessageBox.Show("Название салата: " + ((WithFish)Sal.salat[i]).GetName() + " [" + ((WithFish)Sal.salat[i]).GetType() + "] \nколорийность: " + ((WithFish)Sal.salat[i]).GetCalorie() + "\nрыба: " + ((WithFish)Sal.salat[i]).GetFish());
                    break;
            }
        }
    }
}
